<?php
    include("header.php");
    setTabIndex(2);
    createPage("Liga - Zilveren Toren");
?>

<?php
    if (isset($_SESSION['user'])) $user = $_SESSION['user'];
    mysql_connect(DB_SERVER, DB_USER, DB_PWD);
    mysql_select_db(DB_CATALOG);
    $result = mysql_query("SELECT player_list_id, t.tournament_id, club_id, DATE_FORMAT(date_added,'%d/%m/%Y %k:%i:%s') AS date_added,
        DATE_FORMAT(date_approved,'%d/%m/%Y %k:%i:%s') AS date_approved, DATE_FORMAT(date_modified,'%d/%m/%Y %k:%i:%s') AS date_modified
        from zt_player_list pl join zt_tournament t on t.tournament_id = pl.tournament_id
        where t.isCurrent = 1 and pl.inactive = 0 order by club_id, date_approved desc");

    $playerLists = array();
    while ($row = mysql_fetch_assoc($result)) {
        if (!isset($playerListId) || $playerListId != $row['player_list_id']) {
            $playerListId = $row['player_list_id'];
            $playerList = new PlayerList;
            $playerList->player_list_id = $row['player_list_id'];
            $playerList->tournament_id = $row['tournament_id'];
            $playerList->club_id = $row['club_id'];
            $playerList->date_added = $row['date_added'];
            $playerList->date_approved = $row['date_approved'];
            $playerList->date_modified = $row['date_modified'];
            array_push($playerLists, $playerList);
        }
    }
?>

<table height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0" bgcolor="#FFFFFF">
	<tr>
		<td id="leftFiller" valign="top" height="100%" rowspan="3" bgcolor="#666666">
			<table border="0" cellpadding="0" cellspacing="0" height="100%" width="8px">
				<tr><td>&nbsp;</td></tr>
			</table>
		</td>
		<td id="header" valign="top" width="100%">
			<table border="0" width="100%" cellpadding="3" cellspacing="0" bgcolor="#10425b">
                <tr>
                    <td bgcolor="#666666" width="40%">
                        <?php include("inc_title.html"); ?>
                    </td>
                    <td bgcolor="#666666" align="right" valign="top">&nbsp;
                          <span class="headerSmall">Huidige versie PLAYER.DBF: <?=CURRENT_PLAYER_DBF?>
                        <?php
                        if (isset($user) && $user->club_id == 100) {
                        ?>
                        <br/>
                        <a class="headerSmall" href="import_player.php">laad andere versie</a>
                        <?php
                        }
                        ?>
                        </span>
                    </td>
                </tr>
            </table>
            <table align="center" border="0" width="100%" height="90%" cellpadding="0" cellspacing="0" style="border-top:#BCDD10 4px solid;">
                <tr>
                    <?php include("inc_sublinks.php"); ?> 
                </tr>
				<tr><td colspan="2" nowrap bgcolor="#BCDD10" height="4"><img src="../../assets/images/spacer.gif" alt="" height="1" width="1"></td></tr>
				<tr>
					<td>&nbsp;</td>
					<td valign="top">
						<table align="left" cellspacing="10" width="100%">
							<tr>
								<td>
                                    <span class="blackHeaderLarge"><?=CURRENT_ZT_TOURNAMENT?> - Spelerslijsten</span>
									<br>&nbsp;<br>
									<em>Opmerking : spelerslijsten worden enkel gepubliceerd na goedkeuring door de ligatornooileider (dus niet na indiening).</em>
									<br>&nbsp;<br>
                                    <?php
                                    if (isset($user) && $user->club_id != 100 ) {
                                         $result = mysql_query("select clubname from club where club_id = ".$user->club_id);
                                         $row = mysql_fetch_assoc($result);
                                         $clubname = $row['clubname'];
                                         $result = mysql_query("SELECT 1 from zt_team te 
                                         	join zt_tournament t on t.tournament_id = te.tournament_id 
                                         	where t.iscurrent = 1 and club_id = ".$user->club_id);
                                         if ( mysql_num_rows($result) < 1 ) {
                                    ?>
                                    <img src="../../assets/images/24x24/shadow/users4.gif" border="0" alt="Schrijf aantal ploegen in" />
                                    Schrijf aantal ploegen in voor <strong style="color:#993366;font-size:1.2em"><?=$clubname?></strong>
                                    <br>&nbsp;</br>
                                    <table border="0" width="30%">
                                    	<tr>
                                    		<td>&nbsp;</td>
                                    		<td><strong>Reeks 1</strong></td>
                                    		<td><strong>Reeks 2</strong></td>
                                    		<td><strong>Reeks 3</strong></td>
                                    	</tr>
                                        <tr>
                                    		<td><strong>Aantal</strong></td>
                                            <td><input type="text" name="nrOfTeams1" size="5" maxlength="1" class="yellowBox" style="text-align: center;" onblur="storeClubTeams(this.value,<?=$user->club_id?>,'1', '')" /></td>
                                            <td><input type="text" name="nrOfTeams2" size="5" maxlength="1" class="yellowBox" style="text-align: center;" onblur="storeClubTeams(this.value,<?=$user->club_id?>,'2', '')" /></td>
                                            <td><input type="text" name="nrOfTeams3" size="5" maxlength="1" class="yellowBox" style="text-align: center;" onblur="storeClubTeams(this.value,<?=$user->club_id?>,'3', '')" /></td>
                                    	</tr>
                                    </table>
                                    <br>
                                    <a href="view_players_list.php?action=reset"><img src="../../assets/images/24x24/shadow/recycle.gif" border="0" alt="Reset aantal ploegen"/>
                                    &nbsp;&nbsp;Reset&nbsp;&nbsp;</a>
                                    <a href="insert_player_list.php"><img src="../../assets/images/24x24/shadow/document_add.gif" border="0" alt="Voeg spelerslijst toe" />
                                    &nbsp;&nbsp;Ga naar invoer spelerslijst</a>
                                    <br>&nbsp;<br>
                                    <?php
                                    	} else {
                                    		$result = mysql_query("SELECT 1 from zt_player_list pl 
                                    			join zt_tournament t on t.tournament_id = pl.tournament_id 
                                    			where t.iscurrent = 1 and club_id = ".$user->club_id);
                                        	
                                    		if ( mysql_num_rows($result) < 1 ) {
                                    ?>
                                    <a href="insert_player_list.php"><img src="../../assets/images/24x24/shadow/document_add.gif" border="0" alt="Voeg spelerslijst toe" />
                                    &nbsp;&nbsp;Voeg spelerslijst toe</a>
                                    <br>&nbsp;<br>
                                    <?php
                                         	}
                                    	}
                                    }
                                    
                                    if (isset($_GET['msg']) == true) {
									?>
										<span class="error" id="noKeyFound"><?=$_GET['msg']?></span>
                                    <?php
                                    }
									?>
									<table width="100%" border="0" cellpadding="2" cellspacing="0">
                                    <?php
                                    if (count($playerLists) == 0) {
                                    ?>
                                        <tr>
											<td colspan="6"><strong>Op dit moment zijn er nog geen spelerslijsten goedgekeurd.</strong></td>
										</tr>
                                    <?php
                                    } else {
                                    ?>
                                        <tr>
                                            <td width="5%" style="border-bottom:#DDDDDD solid 1px">&nbsp;</td>
											<td width="5%" style="border-bottom:#DDDDDD solid 1px"><strong>Clubnr</strong></td>
											<td width="35%" style="border-bottom:#DDDDDD solid 1px"><strong>Clubnaam</strong></td>
											<td width="15%" style="border-bottom:#DDDDDD solid 1px"><strong>Ingediend op</strong></td>
											<td width="15%" style="border-bottom:#DDDDDD solid 1px"><strong>Aanvaard op</strong></td>
											<td width="15%" style="border-bottom:#DDDDDD solid 1px"><strong>Laatste wijziging</strong></td>
										</tr>
                                    <?php
                                        foreach ($playerLists as $item) {
	                                    	$result = mysql_query("SELECT clubname from club where club_id = ".$item->club_id);
	                                        $row = mysql_fetch_assoc($result);
	                                        $clubname = $row['clubname'];
	                                        mysql_free_result($result);
                                    ?>
										<tr>
                                    <?php
                                            if (isset($user)) {
                                            	$result = mysql_query("select player_list_id from zt_player_list where
                                                	club_id = ".$user->club_id." and date_added = (select max(date_added) from
                                                    zt_player_list pl join zt_tournament t on t.tournament_id = pl.tournament_id
                                                    where t.isCurrent = 1 and club_id = ".$user->club_id.") order by player_list_id desc");
                                                $row = mysql_fetch_assoc($result);
                                                $player_list_id = $row['player_list_id'];
                                                	
                                                if ($user->club_id == $item->club_id && $item->player_list_id == $player_list_id) {
                                    ?>
                                            <td style="border-bottom:#DDDDDD solid 1px"><a href="edit_player_list.php?player_list_id=<?=$item->player_list_id?>"><img src="../../assets/images/16x16/shadow/document_edit.gif" border="0" alt="Wijzig uw spelerslijst"/></a></td>
                                    <?php
                                                } else if ( $user->club_id == 100 && $item->date_approved == null) {
                                    ?>
                                            <td style="border-bottom:#DDDDDD solid 1px"><a href="approve_player_list.php?player_list_id=<?=$item->player_list_id?>"><img src="../../assets/images/16x16/shadow/document_view.gif" border="0" alt="Valideer spelerslijst"/></a></td>
                                    <?php
                                                } else {
                                    ?>
                                            <td style="border-bottom:#DDDDDD solid 1px">&nbsp;</td>
                                    <?php
                                                }
                                            } else {
                                    ?>
                                            <td style="border-bottom:#DDDDDD solid 1px">&nbsp;</td>
                                    <?php
                                            }

                                        	if ($item->date_approved <> null ) {
                                    ?>
                                        	<td style="border-bottom:#DDDDDD solid 1px"><a href="player_list_detail.php?player_list_id=<?=$item->player_list_id?>"><?=$item->club_id?></a></td>
                                    <?php
                                            } else {
                                    ?>
                                            <td style="border-bottom:#DDDDDD solid 1px"><?=$item->club_id?></td>
                                    <?php
                                            }

                                            if (empty($item->date_approved)) {
                                            	$item->date_approved = "&nbsp;";
                                            }

                                            if (empty($item->date_modified)) {
                                            	$item->date_modified = "&nbsp;";
                                            }
									?>
											<td style="border-bottom:#DDDDDD solid 1px"><?=$clubname?></td>
											<td style="border-bottom:#DDDDDD solid 1px"><?=$item->date_added?></td>
											<td style="border-bottom:#DDDDDD solid 1px"><?=$item->date_approved?></td>
											<td style="border-bottom:#DDDDDD solid 1px"><?=$item->date_modified?></td>
										</tr>
                                    <?php
                                        }
	                                }
                                    ?>
									</table>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
			</table>
		</td>
	</tr>
</table>

</body>
</html>
